import { Power } from './../../power/entities/power.entity';
import { ObjectType, Field } from '@nestjs/graphql';
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { CommonSchema } from 'src/common/mongodb/commonSchema';

@ObjectType({ description: '角色数据' })
@Schema({ collection: 'RoleData' })
export class Role extends CommonSchema {
  @Field(() => String, { description: '角色名' })
  @Prop()
  name: string;

  @Field(() => String, { nullable: true, description: 'code' })
  @Prop()
  code: string;

  @Field(() => [Power], { description: '权限列表' })
  @Prop({ type: [{ type: String, ref: 'Power' }] })
  powers: number[];

  @Field(() => String, { nullable: true, description: '描述' })
  @Prop(() => String)
  description: string;
}

export type RoleDocument = Role & Document;
export const RoleSchema = SchemaFactory.createForClass(Role);
